package com.leo;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.stage.Stage;

import java.net.URL;

public class MediaPlayerDemo extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        URL url = this.getClass().getClassLoader().getResource("bound/1.mp3");
        Media media = new Media(url.toExternalForm());
        MediaPlayer mp = new MediaPlayer(media);

        Button play = new Button("播放");
        Button pause = new Button("暂停");

        AnchorPane root = new AnchorPane();
        root.getChildren().addAll(play, pause);
        AnchorPane.setLeftAnchor(pause, 200d);

        Scene scene = new Scene(root);
        primaryStage.setScene(scene);
        primaryStage.setWidth(1000);
        primaryStage.setHeight(500);
        primaryStage.centerOnScreen();
        primaryStage.setTitle("AudioClipDemo");
        primaryStage.show();

        play.setOnAction(event -> {
            mp.play();
        });

        pause.setOnAction(event -> {
//            mp.stop();
            mp.pause();
        });
    }
}
